package edu.sctu.jsoup.service;

import edu.sctu.jsoup.repo.TravelInfoRepo;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class TravelInfoService {
    @Autowired
    private TravelInfoRepo travelInfoRepo;
    public void run() {
        try {
            Document document = Jsoup.connect("https://www.tripadvisor." +
                    "cn/TourismBlog-t6026.html").get();
            System.out.println(document.body());
            Elements elements = document.select("body");
            for (Element element : elements) {

                String pubDate = element.select("dl").first().text();

                String title = element.select("a").first().text();

                String url = element.select("a").attr("herf");
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    }